package Test;

import org.junit.Assert;
import org.junit.Test;

import Command.Condition;

public class TestCondition {

	@Test
	public void testMayBeCondition()
	{
		// Test case 1
		String tc1 = "a > 0";		
		boolean actual1 = Condition.mayBeCondition(tc1);		
		Assert.assertEquals("TC 1",true, actual1);
		
		// Test case 2
		String tc2 = "a = 0";
		boolean actual2 = Condition.mayBeCondition(tc2);
		Assert.assertEquals("TC 2",true, actual2);
		
		// Test case 3
		String tc3 = "a  = 0";
		boolean actual3 = Condition.mayBeCondition(tc3);
		Assert.assertEquals("TC 3",true, actual3);
		
		// Test case 4
		String tc4 = "a =  0";
		boolean actual4 = Condition.mayBeCondition(tc4);
		Assert.assertEquals("TC 4",true, actual4);
		
		// Test case 5
		String tc5 = "a    =    0";
		boolean actual5 = Condition.mayBeCondition(tc5);
		Assert.assertEquals("TC 5",true, actual5);
		
		// Test case 6
		String tc6 = "a >= 0";
		boolean actual6 = Condition.mayBeCondition(tc6);
		Assert.assertEquals("TC 6",true, actual6);
		
		// Test case 7
		String tc7 = "a=0";
		boolean actual7 = Condition.mayBeCondition(tc7);
		Assert.assertEquals("TC 7",true, actual7);
		
		// Test case 8
		String tc8 = "a!=0";
		boolean actual8 = Condition.mayBeCondition(tc8);
		Assert.assertEquals("TC 8",true, actual8);
		
		// Test case 9
		String tc9 = "'a ''= 0";
		boolean actual9 = Condition.mayBeCondition(tc9);
		Assert.assertEquals("TC 9", false, actual9);
		
		// Test case 10
		String tc10 = "'a ''=' 0";
		boolean actual10 = Condition.mayBeCondition(tc10);
		Assert.assertEquals("TC 10", false, actual10);
		
		// Test case 11
		String tc11 = "'a '=' 0'";
		boolean actual11 = Condition.mayBeCondition(tc11);
		Assert.assertEquals("TC 11", true, actual11);
		
		// Test case 12
		String tc12 = "   = 0";
		boolean actual12 = Condition.mayBeCondition(tc12);
		Assert.assertEquals("TC 12", false, actual12);
		
		// Test case 13
		String tc13 = "a '==' 0";
		boolean actual13 = Condition.mayBeCondition(tc13);
		Assert.assertEquals("TC 13", false, actual13);
		
		// Test case 14
		String tc14 = "a == 0";
		boolean actual14 = Condition.mayBeCondition(tc14);
		Assert.assertEquals("TC 14", false, actual14);
		
		// Test case 15
		String tc15 = " a  = ";
		boolean actual15 = Condition.mayBeCondition(tc15);
		Assert.assertEquals("TC 15", false, actual15);
	}
	
	@Test
	public void testGetOperandsAndOperator()
	{
		// TestCase 1
		String tc1 = "a>0";
		String[] actual1 = Condition.getOperandsAndOperator(tc1);
		String[] expect1 = new String[]{"a", ">", "0"};		
		Assert.assertArrayEquals("TC 1", actual1, expect1);
		
		// TestCase 2
		String tc2 = "   a  >  0   ";
		String[] actual2 = Condition.getOperandsAndOperator(tc2);
		String[] expect2 = new String[]{"a", ">", "0"};		
		Assert.assertArrayEquals("TC 2", actual2, expect2);
		
		// TestCase 3
		String tc3 = "   a  >=  0   ";
		String[] actual3 = Condition.getOperandsAndOperator(tc3);
		String[] expect3 = new String[]{"a", ">=", "0"};		
		Assert.assertArrayEquals("TC 3", actual3, expect3);
		
		// TestCase 4
		String tc4 = "   a  >=  '0' ";
		String[] actual4 = Condition.getOperandsAndOperator(tc4);
		String[] expect4 = new String[]{"a", ">=", "'0'"};		
		Assert.assertArrayEquals("TC 4", actual4, expect4);
	}
	
	@Test
	public void testReversePoland()
	{		
		// TestCase 1
		String tc1 = "Luong >= 1";		
		int actual1 = Condition.ReversePoland(tc1, "DB_Test", "NhanVien").size();
		int expect1 = 2;		
		Assert.assertEquals("TC 1", expect1, actual1);
		
		// TestCase 2
		String tc2 = "Luong>=1";		
		int actual2 = Condition.ReversePoland(tc2, "DB_Test", "NhanVien").size();
		int expect2 = 2;		
		Assert.assertEquals("TC 2", expect2, actual2 );
		
		// TestCase 3
		String tc3 = "Luong<=1";		
		int actual3 = Condition.ReversePoland(tc3, "DB_Test", "NhanVien").size();
		int expect3 = 0;
		Assert.assertEquals("TC 3", expect3, actual3);
		
		// TestCase 4
		String tc4 = "((((Luong>=2 or MaNV>=326))) or (MaNV >= 326 and Luong <= 2))";		
		Object actual4 = Condition.ReversePoland(tc4, "DB_Test", "NhanVien");
		Object expect4 = null;
		Assert.assertEquals("TC 4", expect4 , actual4);
		
		// TestCase 5
		String tc5 = "TenNV >= 'Nguyen B' and Luong = 3";		
		int actual5 = Condition.ReversePoland(tc5, "DB_Test", "NhanVien").size();
		int expect5 = 0;
		Assert.assertEquals("TC 5", expect5, actual5);
	}
}
